package com.leetcode.easy;

import com.leetcode.entity.TreeNode;

/**
 * @author zfl
 * @Classname SolutionIsSymmetric
 * @Description TODO
 * @Date 2020/9/2 16:14
 * @Created by zfl
 */
public class SolutionIsSymmetric {

    /**
     * @param root
     * @return
     * @Description 递归
     * 执行用时：0 ms, 在所有 Java 提交中击败了100.00%的用户
     * 内存消耗：38.2 MB, 在所有 Java 提交中击败了24.26%的用户
     */
    public boolean isSymmetric(TreeNode root) {
        return check(root, root);
    }

    public boolean check(TreeNode p, TreeNode q) {
        if(p == null && q == null) {
            return true;
        }
        if(p == null || q == null) {
            return false;
        }

        return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
    }
}
